package org.example;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhengdp
 * @Description 守护线程测试
 * @Date 2022/9/24 12:37
 * @Created by zhengdp
 */
@Slf4j(topic = "c.daemonThreadTest")
public class DaemonThreadTest {

    @SneakyThrows
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while(true){
                if(Thread.currentThread().isInterrupted()){
                    break;
                }
            }
            log.info("t1线程结束");
        },"t1");

        t1.setDaemon(true);
        t1.start();

        Thread.sleep(1000);
        log.info("主线程结束");
    }
}
